/**
 * Created by AllanXu on 7/25/2016.
 */
define(function (require) {
	var Vue = require('vue'),
		Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities'),
		userId = sessionStorage.id;
	// 认证
	var AuthDialog = require('auth_dialog');
	var authDialog = new AuthDialog();
	// 禁用申诉
	var Forbidden = require('forbidden');
	var forbidden = new Forbidden();
	var app = new Vue({
		el: '#uc_myvideo',
		data: {
			// pageIndex: 1,
			videoWidth: 0,
			pageCount: '',
			pageno: 1,
			renderObj: {
				listArr: []
			},
			tabsName: [],
			typeId: '',
			curNum: -1,
			bottomTxt: '',
			picServer: Config.picServer
		},
		methods: {
			init: function () {
                this.videoWidth = (document.body.clientWidth - 30) / 2;
				_(Config.SERVICE.USERCENTER.MYALBUMLIST + '?id=' + userId + app.typeId + '&pageno=' + app.pageno + '&pagesize=10&type=1', {}, function (data) {
					// _(Config.SERVICE.ACTIVITY.LIST+'?id='+4+'&param='+utilities.jsonObjToBase64(param), {}, function(data) {
					if (app.pageno == 1) {
						app.renderObj.listArr = data.pageitems;
						app.pageCount = data.pagecount;
					} else {
						app.renderObj.listArr = app.renderObj.listArr.concat(data.pageitems);
					}
				});
			},
			del: function (id) {
				if (confirm("确定删除？")) {
					_(Config.SERVICE.USERCENTER.ALBUMDEL, {
						"id": id
					}, function (data) {
						if (data.code == 200) {
							app.pageno = 1;
							app.init();
						}
					});
				}
			},
			setMyHead: function (id) {
				if (confirm("设为形象照？")) {
					_(Config.SERVICE.USERCENTER.IMGSAVE, {
						"xgmember.id": userId,
						"id": id
					}, function (data) {
						if (data.code == 200) {
							alert("设置成功~");
						}
					});
				}
			}
		}
	});
	app.init();

	window.onscroll = function () {
		var scrolltop = document.body.scrollTop | document.documentElement.scrollTop;
		var clientHeight = document.documentElement.clientHeight;
		if (scrolltop + clientHeight == document.body.clientHeight) {
			if (app.pageno <= app.pageCount) {
				app.pageno++;
				app.init();
			} else {
				app.bottomTxt = '到底儿了~';
			}
		}
	};

	//图片上传
	$('#pic').AjaxFileUpload({
		action: Config.SERVICE.USERCENTER.IMGUPLOAD + '?type=1',
		onComplete: function (filename, response) {
			_(Config.SERVICE.USERCENTER.IMGTOSERVER, {
				"memberAlbum.memId": userId,
				"memberAlbum.annex.id": response.title
			}, function (data) {
				if (data.code == 200) {
					alert("上传成功~")
					app.pageno = 1;
					app.init();
				}
			});
		}
	});
});